<?php
    include 'konek.php';
    session_start();
    if(!isset($_SESSION['username'])) {
?>
    <script language="javascript">
        alert('anda blm login');
        document.location='../'
    </script>
<?php 
    } else {
        $username = $_SESSION['username'];
        $status = $_SESSION['status'];
    }

    /*if(!isset($_GET['stat']))
    {
        echo "<script>alert('DATA DITAK DITEMUKA');</script";
    }
    else
    {
        $stat=$_GET['stat'];
    }*/
    if($status=='siswa') {
        siswa($username,$status);
    } else {
        guru($username,$status);
    }

    function guru($user,$stat) {
        $first = $_POST['firstname'];
        $last = $_POST['lastname'];
        $ttl = $_POST['ttl'];
        $mapel = $_POST['mapel'];
        $email = $_POST['email'];
        $img = $_POST['image'];
        $syntax = mysql_query(" UPDATE guru set first_name='$first', last_name='$last', ttl='$ttl', mapel='$mapel', email='$email', img='$img' where email='$user'");
?>
    <script language="javascript">
        alert('SUKSES');
        document.location='../page/editprofile.php'
    </script>
<?php 
    }

    function siswa($user,$stat) {
        $first = $_POST['firstname'];
        $last = $_POST['lastname'];
        $kls = $_POST['kls'];
        $email = $_POST['email'];
        $img = $_POST['image'];
        $syntax = mysql_query("update siswa set first_nm='$first', last_nm='$last', kls='$kls', email_sis='$email', img='$img' where email_sis='$user'");
?>
    <script language="javascript">
        alert('SUKSES');
        document.location='../page/editprofile.php'
    </script>
<?php
    }
?>